<?php
/* @var $this AnalysisController */

Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('product-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'proPromotion-form',
		'enableAjaxValidation'=>false,
	)); ?>
	<?php echo $form->hiddenField($model,'zpt_type')?>
	<?php echo $form->errorSummary($model); ?>
	<ul class="form_list form_list2 group ">
		<li class="c_f title"><h3 class="fs_14">创建抢购秒杀</h3></li>
		<li class="c_f"><span class="tit"><em class="xing">*</em>抢购秒杀标题：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zpt_title',array('class'=>'t_ipt w_300'))?>
				<span id="ProTuan_zpt_titleTip"></span>
			</div>
		</li>
		<li class="c_f"><span class="tit"><em class="xing">*</em>活动时间：</span>
			<div class="cont f_l">
					<?php echo $form->textField($model,'zpt_start_time',array('onclick'=>"WdatePicker()"))?>
					<span class="c_999">-</span>
					<?php echo $form->textField($model,'zpt_end_time',array('onclick'=>"WdatePicker()"))?>
					<span id="ProTuan_zpt_start_timeTip"></span>
			</div>
		</li>
		<li class="c_f"><span class="tit"><em class="xing">*</em>添加抢购秒杀宝贝：</span>
			<div class="cont f_l">
				<div class="group_box">
					<table width="100%" cellpadding="0" cellspacing="0">
						<tr>
							<td width="22%" class="title">商品名称：<?php echo $form->hiddenField($model,'zp_id')?></td>
							<td width="78%" class="c_666" id="tuan_pro_name"><?php echo empty($model->product)?'请选择产品':$model->product->zp_name?></td>
						</tr>
						<tr class="">
							<td class="title">展示图片：</td>
							<td>
								<div class="c_img c_img120"><a href="javascript:" title="">
									<?php echo CHtml::image(empty($model->zpt_pic)?'/images/cert_img.jpg.':$model->zpt_pic,'',array('id'=>'img1','width'=>'120px','height'=>'120px'))?></a>
								</div>
								<div class="upload f_l">
									<?php echo CHtml::link('上传图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b>'.CHtml::fileField('image','',array('id'=>'uploadimg1','multiple'=>true)),'javascript:',array('class'=>'mem_bgx link_btn filelink mr20','onclick'=>"uploadimg('1')"))?>
									<?php echo $form->hiddenField($model,'zpt_pic',array('id'=>'proimage1'))?>
									<p class="c_999">可以上传图片，不传上默认产品图片</p>
								</div>
							</td>
						</tr>
						<tr>
							<td class="title">秒杀价格：<?php echo $form->hiddenField($model,'zpt_saleprice',array('class'=>'zp_price_hidden'))?></td>
							<td>
								<?php echo $form->textField($model,'zpt_price',array('class'=>'t_ipt w_80'))?>
								<span class="c_999">目前原价：<span class="zp_price"><?php echo empty($model->product)?'0':$model->product->zp_price?></span>* 设置团购价格</span>
							</td>
						</tr>
						<tr>
							<td class="title">最大销售量：</td>
							<td>
								<?php echo $form->textField($model,'zpt_limit_nums',array('class'=>'t_ipt w_80'))?>
								<span class="c_999">目前库存：<span class="zp_inventory"><?php echo empty($model->product)?'0':$model->product->zp_inventory?></span>* 团购出售的最大数量，设置空或0则无限制</span>
							</td>
						</tr>
						<tr>
							<td class="title">最小销售量：</td>
							<td>
								<?php echo $form->textField($model,'zpt_min_nums',array('class'=>'t_ipt w_80'))?>
								<span class="c_999">目前库存：<span class="zp_inventory"><?php echo empty($model->product)?'0':$model->product->zp_inventory?></span>* 如果销售量小于此数值，团购无效，设置空或0则无限制</span>
							</td>
						</tr>
					</table>
				</div>
				<p><a class="mem_bgx link_btn" onclick="addmatch()" href="javascript:" title="">选择抢购秒杀宝贝<b class="mem_bgx left"></b><b class="mem_bgx right"></b></a><a class="mem_bgx link_btn" onclick="return addmatch();" href="javascript:" title="" style="display:none;">重新选择宝贝<b class="mem_bgx left"></b><b class="mem_bgx right"></b></a></p>
			</div>
		</li>
		<li class="c_f d_n"><span class="tit">秒杀详情：</span>
			<div class="cont f_l">
				<?php  $this->widget('ext.keditor.KEditor',array(
			            'model'=>$model,  //传入form model
			            'name'=>'zpt_content', //设置name
			            'properties'=>array(
			                //设置接收文件上传的action
			                'uploadJson'=>'/Attachment/GetAjax',
			                //设置浏览服务器文件的action，这两个就是上面配置在/admin/default的
			             //   'fileManagerJson'=>'/Attachment/GetAjax',
			                'newlineTag'=>'br',
			                'allowFileManager'=>true,
			                //传值前加js:来标记这些是js代码
			                'afterCreate'=>"js:function() {
			                        K('#ChapterForm_all_len').val(this.count());
			                        K('#ChapterForm_word_len').val(this.count('text'));
			                    }",
			                'afterChange'=>"js:function() {
			                        K('#ChapterForm_all_len').val(this.count());
			                        K('#ChapterForm_word_len').val(this.count('text'));
			                    }",
			            ),
			            'textareaOptions'=>array(
			                'style'=>'width:670px;height:261px;',
			            )
				  )); ?>
			</div>
		</li>
		<li class="c_f save_link"><span class="tit">&nbsp;</span>
			<div class="cont f_l">
				<?php echo CHtml::submitButton(Yii::t('cmp','Save Promotion'),array('class'=>'mem_btn mem_btn20 mr5'))?>
				<?php echo CHtml::resetButton(Yii::t('cmp','Reset'),array('class'=>'mem_btn mem_btn07'))?>
			</div>
		</li>
	</ul>
<?php $this->endWidget(); ?>

<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/My97DatePicker/WdatePicker.js"></script>

<div class="d_n" id="product_list">
<div class="d-title" style="display: block; ">选择产品</div>
<a class="d-close" href="javascript:" style="display: block;" onclick="addmatch()">×</a>
<div class="pro_filter c_f search-form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl($this->route),
	'method'=>'get',
)); ?>
	<label>产品标题：</label>
	<?php echo $form->textField($product,'zp_name',array('class'=>'t_ipt w_180'))?>
	<label>产品货号：</label>
	<?php echo $form->textField($product,'pro_no',array('class'=>'t_ipt w_180'))?>
	<?php echo CHtml::submitButton(Yii::t('cmp','Search'),array('class'=>'mem_bgx mem_btn01'))?>
<?php $this->endWidget(); ?>
</div>

<div style="height:300px;overflow-y:auto;">
<!-- 列表 -->
<?php 
	$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'product-grid',
	'dataProvider'=>$product->search(40),//数据源
	//'filter'=>$product,//设置过滤器，筛选输入框
	'template'=>'{items}',
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'class' => 'CCheckBoxColumn',
			'checkBoxHtmlOptions' => array('name' => 'id[]','class'=>'chk d_n'),
			'htmlOptions'=>array('width'=>'6%'),
		),
		array('class'=>'CLinkColumn',
				'header'=>'产口图片',
				'labelExpression'=>'Tool::thumb($data->zp_pic,50,50,$data->zp_pic)',
				'urlExpression'=>'array("/home/product/detail","id"=>$data->zp_id)',
				'linkHtmlOptions'=>array('width'=>'50','height'=>'50'),
				'htmlOptions'=>array('width'=>'10%'),
		),
		array('class'=>'CLinkColumn',
				'header'=>'产品标题',
				'labelExpression'=>'mb_substr($data->zp_name,0,12,"utf8")',
				'urlExpression'=>'array("/home/product/detail","id"=>$data->zp_id)',
				'linkHtmlOptions'=>array('class'=>'c_06c'),
				'htmlOptions'=>array('width'=>'30%','class'=>'t_c'),
		),
		array('name'=>'pro_no',
				'value'=>'$data->pro_no',
				'htmlOptions'=>array('width'=>'10%','class'=>'t_c'),
		),
		array('name'=>'zp_price',
				'value'=>'$data->zp_price',
				'htmlOptions'=>array('width'=>'15%','class'=>'t_c'),
		),
		array('name'=>'zp_inventory',
				'value'=>'$data->zp_inventory',
				'htmlOptions'=>array('width'=>'15%','class'=>'t_c'),
		),
		array('class'=>'CLinkColumn',
				'header'=>'操作',
				'labelExpression'=>'"选择"',
				'urlExpression'=>'"javascript:"',
				'linkHtmlOptions'=>array('class'=>'mem_btn mem_btn13 pro_item'),
				'htmlOptions'=>array('width'=>'14%'),
		),
	)
));
?>
</div>
<div class="d-footer">
<div class="t_l f_l" id="select_pro" style="padding:10px 20px;">
<?php if(!empty($model->products)){ foreach($model->products as $val){?>
<span class="mr10 pro" id="select_pro_<?php echo $val->zp_id?>" pid="<?php echo $val->zp_id?>"><?php echo mb_substr($val->zp_name,0,16,'utf8')?></span>
<?php }}?>
</div>
<div class="d-buttons" style=""><input type="button" class="d-button d-state-highlight" value="确定" onclick="addmatch()"></div>
</div>
</div>



<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js"></script>  
<script type="text/javascript">
//选择
$('.pro_item').live('click',function(){
	var pid = $(this).parent().parent().find('.chk').val()
	var pic = $(this).parent().parent().find('td').eq(1).find('img').attr('alt');
	var pnametext = $(this).parent().parent().find('td').eq(2).text();
	var pprice = $(this).parent().parent().find('td').eq(4).text();
	var inventory = $(this).parent().parent().find('td').eq(5).text();
	if($(this).text()=='删除'){
		$('#tuan_pro_name').text("请选择商品");
		$('#img1').attr('src','/images/cert_img.jpg');
		$('#proimage1').attr('value','');
		$('#ProTuan_zp_id').val('');
		$('#select_pro').html('');
		$('.zp_price').text("");
		$('.zp_price_hidden').val("");
		$('.zp_inventory').text("");
		$(this).text('选择');
		$(this).removeClass('c_06c');
		$(this).addClass('mem_btn mem_btn13');
		$(this).prev('label').remove();return;
	}
	if($('#ProTuan_zp_id').val()==pid){
		art.dialog({title:'警告：',content:'相同产品请勿重复添加',okValue:"确定",ok:function(){return true;}});
		$(this).text('删除');
		$(this).removeClass('mem_btn mem_btn13');
		$(this).addClass('c_06c');
		$(this).before('<label class="mr10">已选择</label>');
	}else{
		$('.pro_item').text('选择');
		$('.pro_item').removeClass('c_06c');
		$('.pro_item').addClass('mem_btn mem_btn13');
		$('.pro_item').prev('label').remove();
		$('#tuan_pro_name').text(pnametext);
		$('#img1').attr('src',pic);
		$('#proimage1').attr('value',pic);
		$('#ProTuan_zp_id').val(pid);
		$('#select_pro').html('<span class="mr10 pro" id="select_pro_'+pid+'" pid="'+pid+'">'+pnametext+'</span>');
		$('.zp_price').text(pprice);
		$('.zp_price_hidden').val(pprice);
		$('.zp_inventory').text(inventory);
		$(this).text('删除');
		$(this).removeClass('mem_btn mem_btn13');
		$(this).addClass('c_06c');
		$(this).before('<label class="mr10">已选择</label>');
	}
})

//显示弹框
function addmatch(){
	$('#product_list').toggle();
}

//上传图片
function uploadimg (id) {
	   $('#uploadimg'+id).fileupload({         	
	        dataType: 'json',       
	        url: '/Attachment/GetAjax',        
	        success: function (json) {
	               if(json.upfile.errors=='1'){
	               		alert(json.upfile.msg);
	               }else if(json.upfile.errors=='2'){
	               		alert(json.upfile.msg);
	               }else{
		                 //修改按钮图标
		            	 $('#img'+id).attr('src',json.upfile.file);
						 //修改按钮文本
		            	 $('#uploadimg'+id).parent().html('修改图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b><input type="file" id="uploadimg'+id+'" multiple name="image"/>');
						 //修改隐藏域值
	               		 $('#proimage'+id).attr('value',json.upfile.file);
	               } 	
	        }
	    });
};
//删除图片
function removeimg(id){
	$('#img'+id).parent().parent().find('a').eq(0).html('上传图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b><input type="file" id="uploadimg'+id+'" multiple name="image"/>');
	$('#img'+id).attr('src','/images/pro_img.jpg');
	$('#proimage'+id).attr('value','');
}
//弹框拖拽
$(function(){
	$('#product_list').draggable({ handle: '.d-title' });
});
</script>
 
<!-- 表单验证 -->
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/formValidator-4.1.1.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/formValidatorRegex.js"></script>
 <script>
	jQuery(document).ready(function($) {
		$.formValidator.initConfig({theme:"Default",formID:"proPromotion-form",
			onError:function(msg, obj){
						alert(msg);
						return false;
					},
			onsuccess:function(){ return true; }
		});
	})
</script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/cmpValidate.js"></script>